import {rpxToPx} from "../utils/util"
Page({

  data: {
    nav_curr:0,
    list:[],
    list_curr:-1,
    list_no:[],
    pid:'',
    id:'',
    scroll:getApp().globalData.screenHeight - rpxToPx(108)
  },

  
  onLoad(options) {
    this.setData({
      pid:options.pid,
      id:options.id,
      scroll:getApp().globalData.screenHeight - rpxToPx(108)
    })
    if(this.data.pid==3){
      this.cleanlist(1,'list')
      this.cleanlist(2,'list_no')
    }else{
      this.receiveVehiclelist(1,'list')
      this.receiveVehiclelist(2,'list_no')
    }
  },

  cleanlist(status,list){
    getApp().globalData.posts('/index.php/api/ouyoung/contract/sorting/ouyapi/cleanlist',{
      status,
      pid:this.data.pid,
      id:this.data.id,
    }).then(res=>{
      if(res.data.code==1){
        this.setData({
          [list]:res.data.data
        })
      }
    })
  },

  receiveVehiclelist(status,list){
    getApp().globalData.posts('/api/app/user/sorting/ouyoung_api/receiveVehiclelist',{
      status,
      pid:this.data.pid,
      id:this.data.id,
    }).then(res=>{
      if(res.data.code==1){
        this.setData({
          [list]:res.data.data
        })
      }
    })
  },

  change_nav_curr(e){
    let nav_curr = e.currentTarget.dataset.nav_curr;
    this.setData({
      nav_curr
    })
  },
  change_nav(e){
    this.setData({
      nav_curr:e.detail.current
    })
  },

  change_list_curr(e){
    let list_curr = e.currentTarget.dataset.list_curr;
    this.setData({
      list_curr
    })
  },

  bottomTap(){
    if(this.data.list_curr==-1){
      getApp().showToast('请先选择优惠券')
      return
    }
    wx.setStorageSync('car_coupon', this.data.list[this.data.list_curr])
    wx.navigateBack()
  },
  
})